<!--
 * @Description: AJAX
 * @Author: zzj
 * @Date: 2021-09-15 11:41:45
 * @LastEditors: zzj
 * @LastEditTime: 2021-09-15 14:15:51
-->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>AJAX</title>
    <script>
        /*
        //第一步：实例化ajax对象（XMLHttpRequest）
        var x = new XMLHttpRequest();
        //第二步（GET）：创建客户端服务器端连接（使用open方法）。
        var url = "http://81.69.24.232:8001/baseUser/cascadeRoleFindAll";//数据
        //GET请求如果有参数，拼接在地址栏后面
        x.open("GET",url,true);//打开链接（请求方式，URL，异步/同步）
        x.setRequestHeader("Authorization","eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VySWQiOiJNalk9Iiwic3ViIjoiYWRtaW4yIiwiaXNzIjoiMDk4ZjZiY2Q0NjIxZDM3M2NhZGU0ZTgzMjYyN2I0ZjYiLCJpYXQiOjE2MzE2Nzg3ODEsImF1ZCI6InJlc3RhcGl1c2VyIiwiZXhwIjoxNjMxODUxNTgxLCJuYmYiOjE2MzE2Nzg3ODF9.zAEFd6uaLp1joPQnYLjL23k65lLYqqeDoavJDMELwAA");
        x.send(null);  //发送请求(GET方式为null,POST方式为数据)
        //第四步 验证
        x.onreadystatechange = function(){
            if(x.readyState == 4 && x.status==200){
                // var text = x.responseText;
                console.log(x.responseText);//以文本的方式接收返回的数据
                var users = JSON.parse(x.responseText);
            }
        }
        */
        ///*
        //添加一个用户
        //第一步：实例化ajax对象（XMLHttpRequest）
        var x = new XMLHttpRequest();
        //第二步（POST）
        var url = "http://81.69.24.232:8001/baseUser/saveOrUpdate";
        x.open("POST",url,true);
        //var msg = Qs.stringify(obj);
        var msg = "username=zzj2021&password=123321";
        x.setRequestHeader("Authorization","eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VySWQiOiJNalk9Iiwic3ViIjoiYWRtaW4yIiwiaXNzIjoiMDk4ZjZiY2Q0NjIxZDM3M2NhZGU0ZTgzMjYyN2I0ZjYiLCJpYXQiOjE2MzE2Nzg3ODEsImF1ZCI6InJlc3RhcGl1c2VyIiwiZXhwIjoxNjMxODUxNTgxLCJuYmYiOjE2MzE2Nzg3ODF9.zAEFd6uaLp1joPQnYLjL23k65lLYqqeDoavJDMELwAA");
        x.setRequestHeader("Content-type","application/x-www-form-urlencoded; charset=UTF-8");
        x.send(msg);// 数据
        //第四步 验证
        x.onreadystatechange = function(){
            if(x.readyState == 4 && x.status==200){
                console.log(x.responseText);
                console.log("添加成功")
            }
        }
        //*/
        
    </script>
</head>
<body>
    
</body>
</html>